{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!--BOOK_INFORMATION-->\n",
    "<img align=\"left\" style=\"padding-right:10px;\" src=\"figures/PHydro-cover-small.png\">\n",
    "*This is the Jupyter notebook version of the [Python in Hydrology](http://www.greenteapress.com/pythonhydro/pythonhydro.html) by Sat Kumar Tomer.*\n",
    "*Source code is available at [code.google.com](https://code.google.com/archive/p/python-in-hydrology/source).*\n",
    "\n",
    "*The book is available under the [GNU Free Documentation License](http://www.gnu.org/copyleft/fdl.html). If you have comments, corrections or suggestions, please send email to satkumartomer@gmail.com.*"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!--NAVIGATION-->\n",
    "< [Bias Correction](10.04-Bias-Correction.ipynb) | [Contents](Index.ipynb) | [Kalman Filtering](10.06-Kalman-Filtering.ipynb)>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 10.5 PCA\n",
    "\n",
    "主成分分析法(PCA)是一种降低数据维度的工具。有时候几个维度在相互间有显著的相关性，这意味着它们拥有几乎相同的信息，在这种情况下，即使是我们降低了维度，也几乎保留了相同的信息。我们将使用`matplotlib.mlap.PCA`来执行`PCA`。首先我们生成数据并查看它的相关性。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\laihetao\\AppData\\Local\\conda\\conda\\envs\\DataProcess\\lib\\site-packages\\ipykernel_launcher.py:12: RuntimeWarning: covariance is not positive-semidefinite.\n",
      "  if sys.path[0] == '':\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAQgAAADdCAYAAABHcuzXAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4xLCBodHRwOi8vbWF0cGxvdGxpYi5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gn4oAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x25ce936f2e8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "from matplotlib.mlab import PCA\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "# change the default parameters of the plot\n",
    "params = {'font.size': 17}\n",
    "plt.rcParams.update(params)\n",
    "\n",
    "# let us generate 4 dimensional data set\n",
    "mean = 10*np.random.rand(4)\n",
    "cov = np.random.rand(4,4)\n",
    "data = np.random.multivariate_normal(mean,cov,100)\n",
    "names = ['A', 'B', 'C', 'D']\n",
    "\n",
    "plt.matshow(np.corrcoef(data.T), vmax=1, vmin=0)\n",
    "plt.colorbar(shrink=0.6)\n",
    "plt.xticks(range(4), names)\n",
    "plt.yticks(range(4), names)\n",
    "plt.show()\n",
    "plt.close()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "图10.5显示了数据维度间的相关性。偏离对角线的相关性是非零的，这意味着PCA可以降低维度，非对角线条目越高，更多的PCA将能够降低数据的维度。\n",
    "\n",
    "PCA类的实例生成为:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "foo = PCA(data)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "重新缩放的数据由PCA实例的`Y`属性给出。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_new = foo.Y"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "我们可以检查它的相关性。图10.19展示了缩减/新数据的相关性。相关矩阵的非对角元素为零，这意味着数据现在是正交化的。这就是为什么这在水文学中也被称为经验正交函数。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPgAAADVCAYAAAB64z3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h08olw5TRZRLoMzg0cUasZOk9Xek03SoqT9kg5I+lbVXSH3cotYgxcXV2xNNOhsslHS31SvPyjpzLoxmwT1Zdvbbf84cClwOXBjo4ojjjb9S1UHtxoNO5tcCxyy/aPAp4E/rht3pJm4upPjbuB6VXd9i4g3mLFn8NrOJtXjW6u/7wI+UJfDkZfatp+q3nfyqO+NKJ49bsCbdDZ5fR/bh4GXgJOGDTruQbZV/9Wo2rHsBtjEcWMOHdFd3+fQ3q8s3bl5lZc2Sdq37PG87fllj5t0Nmnc/aRv5IBLejewCKy48XpV8DzAiXrH7FyvF7FObF825lubdDbp7/OMpGOAtwMHhw060hJd0hbgZuBz9gxdcBvRfbWdTarH11R/XwncU5fDJjP4sZL2AxuAw8DtwKdGqTwihmvY2eSvgNslPUFv5r6qbtzagNueO7LSI6KJBp1NXgF+fpQxc8FKRMES8IiCJeARBUvAIwqWgEcULAGPKFgCHlGwBDyiYAl4RMES8IiCJeARBUvAIwqWgEcULAGPKFgCHlGwBDyiYAl4RME0qVurSXoe+O4Eht4MvDCBcScpNU/eJOs9w/aWCY09URML+KRI2md7x7TrGEVqnryu1bteskSPKFgCHlGwLgZ8vn6XmZOaJ69r9a6Lzn0Hj4jmujiDR0RDCXhEwRLwiIIl4BEFS8AjCvb/M/fLoRd46MUAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x25ce936ff98>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.matshow(np.corrcoef(data_new.T), vmax=1, vmin=0)\n",
    "plt.colorbar(shrink=0.6)\n",
    "plt.xticks(range(4), names)\n",
    "plt.yticks(range(4), names)\n",
    "plt.show()\n",
    "plt.close()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "图10.16:执行PCA后数据的相关性。所有的维度都是非相关的，这是PCA所预期的。\n",
    "\n",
    "我们可以通过使用属性`fracs`检查每个维度所解释的方差。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 0.6101896   0.15971046  0.12876526  0.10133468]\n"
     ]
    }
   ],
   "source": [
    "print(foo.fracs)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "这告诉我们一维只能解释9%的变异，我们可以在不损失很多数据的情况下放弃它。"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
